package com.moehu.back.controller.app;

import com.moehu.back.annotation.AppRestController;
import com.moehu.back.annotation.UserLoginToken;
import com.moehu.back.controller.base.BaseService;
import com.moehu.back.model.ResultModel;
import com.moehu.back.model.UserModel;
import com.moehu.back.model.response.LoginResponseModel;
import com.moehu.back.model.response.OpusSearchUser;
import com.moehu.back.service.impl.UserServiceImpl;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@Slf4j
@RestController
@RequestMapping(value = "/user")
@AppRestController
@Api(tags = "User 用户相关的接口")
public class UserController extends BaseService {

    @Autowired
    private UserServiceImpl userService;

    @ApiOperation(value="用户登录", notes="用户登录成功后，接口会返回token字段，需要前端自己存储，并在请求头 token 中携带")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_phone", value = "手机号（前端自己验证手机号合法性）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sms_code", value = "短信验证码", required = true, dataType = "String")})
    @PostMapping("/Login")
    public ResultModel<LoginResponseModel<UserModel>> Login(@RequestBody UserModel User) {
        return userService.UserLogin(User);
    }


    @ApiOperation(value="用户注册", notes="用户注册接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_nickname", value = "昵称",
                    required = true, dataType = "String"),
            @ApiImplicitParam(name = "user_phone", value = "手机号（前端自己验证手机号合法性）",
                    required = true, dataType = "String"),
            @ApiImplicitParam(name = "sms_code", value = "短信验证码", required = true, dataType = "String")
    })
    @PostMapping("/Reg")
    public ResultModel<LoginResponseModel<UserModel>> Register(@RequestBody UserModel User) {
        return userService.UserRegister(User);
    }



    @ApiOperation(value="获取用户的基本信息", notes="传入用户的user_id，获取用户的个人空间基本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id", value = "用户的user_id", required = true, dataType = "Number"),
    })
    @PostMapping("/UserInfo")
    public ResultModel<LoginResponseModel<UserModel>> UserInfo(@RequestBody UserModel User) {
        return userService.UserInfo(User);
    }


    @ApiOperation(value="个人空间【关注】获取我关注的所有用户", notes="传入用户的user_id，获取我关注的所有用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id", value = "用户的user_id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "page", value = "请求的页数", required = true, dataType = "String", defaultValue="1"),
            @ApiImplicitParam(name = "count", value = "每页作品数，默认15", required = true, dataType = "String", defaultValue="15"),
    })
    @PostMapping("/FollowUserList")
    public ResultModel<LoginResponseModel<OpusSearchUser>> FollowUserList(@RequestBody Map<String,String> User) {
        return userService.FollowUserList(User);
    }

    @ApiOperation(value="个人空间【粉丝】获取关注我的粉丝", notes="传入用户的user_id，获取关注我的粉丝")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id", value = "用户的user_id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "page", value = "请求的页数", required = true, dataType = "String", defaultValue="1"),
            @ApiImplicitParam(name = "count", value = "每页作品数，默认15", required = true, dataType = "String", defaultValue="15"),
    })
    @PostMapping("/FansUserList")
    public ResultModel<LoginResponseModel<OpusSearchUser>> FansUserList(@RequestBody Map<String,String> User) {
        return userService.FansUserList(User);
    }


    @UserLoginToken
    @ApiOperation(value="用于编辑个人资料", notes="编辑个人资料接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_head_img", value = "头像的图片地址，如果用户没有修改，默认数值传空字符串: '' ", required = true, dataType = "String"),
            @ApiImplicitParam(name = "user_nickname", value = "昵称，如果用户没有修改，默认数值传空字符串: '' ", required = true, dataType = "String"),
            @ApiImplicitParam(name = "user_autograph", value = "简介，也就是签名，如果用户没有修改，默认数值传空字符串: '' ", required = true, dataType = "String"),
            @ApiImplicitParam(name = "user_sex", value = "性别，如果用户没有修改，默认数值传空字符串: ''", required = true, dataType = "String"),
            @ApiImplicitParam(name = "user_birthday", value = "出生日期，格式：1995-03-24，如果用户没有修改，默认数值传空字符串: '' ", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "user_address", value = "地区", required = true, dataType = "String"),
    })
    @PostMapping("/EditUserInfo")
    public ResultModel<LoginResponseModel<UserModel>> EditUserInfo(@RequestBody UserModel User) {
        return userService.EditUserInfo(User);
    }

}
